import java.util.Arrays;

/**
 * Created by 20155322 on 2017/4/21.
 */
public class Complex {
    private double r;
    private double i;

    public Complex(double r, double i) {
        this.r = r;
        this.i = i;
    }

    public static double getRealPart(double r) {
        return r;
    }

    public static double getImagePart(double i) {
        return i;
    }

    public Complex ComplexAdd(Complex c) {
        return new Complex(r + c.r, i + c.i);
    }

    public Complex ComplexSub(Complex c) {
        return new Complex(r - c.r, i - c.i);
    }

    public Complex ComplexMulti(Complex c) {
        return new Complex(r * c.r - i * c.i, r * c.i + i * c.r);
    }

    public Complex ComplexDiv(Complex c) {
        return new Complex((r * c.i + i * c.r) / (c.i * c.i + c.r * c.r), (i * c.i + r * c.r) / (c.i * c.i + c.r * c.r));
    }

    //测试一
    public static char String_charAt(String str, int i) {
        return str.charAt(i);
    }

    //取测试一结果
    public static char getString_charAt(String str, int i) {
        return String_charAt(str, i);
    }

    //测试二
    public static String[] String_split(String str) {
        String[] strsort = str.split(":");
        return strsort;
    }

    //取测试二结果
    public static String[] getString_split(String str) {
        return String_split(str);
    }

    //测试三
    public static String[] Arrays_sort(String[] str3) {
        Arrays.sort(str3);
        return str3;
    }

    //取测试三结果
    public static String[] getArrays_sort(String[] str3) {
        return Arrays_sort(str3);
    }

    //测试四
    public static double[] Arrays_binarySearch(double[] str4) {
        Arrays.sort(str4);
        return str4;
    }

    //取测试四结果
    public static double[] getArrays_binarySearch(double[] str4) {
        return Arrays_binarySearch(str4);
    }

    public String toString() {
        String s = " ";
        if (i > 0)
            s = r + "+" + i + "i";
        if (i == 0)
            s = r + "";
        if (i < 0)
            s = r + " " + i + "i";
        return s;
    }
}
